<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "comment".
 *
 * @property integer $id
 * @property integer $user_id
 * @property integer $question_id
 * @property string $comment_content
 * @property string $url
 * @property string $comment_time
 * @property integer $class1_id
 * @property integer $class2_id
 * @property integer $like_num
 * @property integer $play_num
 * @property string $like_ids
 * @property integer $is_up
 * @property integer $tnum
 *
 * @property Class1 $class1
 * @property Class2 $class2
 * @property User $user
 */
class Comment extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'comment';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'question_id', 'class1_id', 'class2_id', 'tnum'], 'required'],
            [['user_id', 'question_id', 'class1_id', 'class2_id', 'like_num', 'play_num', 'is_up', 'tnum'], 'integer'],
            [['comment_content'], 'string'],
            [['comment_time'], 'safe'],
            [['url', 'like_ids'], 'string', 'max' => 255],
            [['class1_id'], 'exist', 'skipOnError' => true, 'targetClass' => Class1::className(), 'targetAttribute' => ['class1_id' => 'id']],
            [['class2_id'], 'exist', 'skipOnError' => true, 'targetClass' => Class2::className(), 'targetAttribute' => ['class2_id' => 'id']],
            [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'user_id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => 'User ID',
            'question_id' => 'Question ID',
            'comment_content' => 'Comment Content',
            'url' => 'Url',
            'comment_time' => 'Comment Time',
            'class1_id' => 'Class1 ID',
            'class2_id' => 'Class2 ID',
            'like_num' => 'Like Num',
            'play_num' => 'Play Num',
            'like_ids' => 'Like Ids',
            'is_up' => 'Is Up',
            'tnum' => 'Tnum',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getClass1()
    {
        return $this->hasOne(Class1::className(), ['id' => 'class1_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getClass2()
    {
        return $this->hasOne(Class2::className(), ['id' => 'class2_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(User::className(), ['user_id' => 'user_id']);
    }
}
